<?php

if(submitcheck('addsubmit')) {
	//print_r($_POST); exit;
	$_POST['config'] = serialize($_POST['config']);
	$_POST['dateline'] = $_G['timestamp'];
	$_POST['uid'] = $_SESSION['uid'];
	$_POST['status'] = 0;
	
	if(DB::insert('renthouse', $_POST)) {
		showmessage('rent_add_done', $_G['url']);
	} else {
		showmessage('rent_add_error', $_G['url']);
	}
	//exit;
}

if(submitcheck('editsubmit')) {

	$rid = intval($_GET['rid']);
	$_POST['config'] = serialize($_POST['config']);
	$_POST['dateline'] = $_G['timestamp'];
	$_POST['uid'] = $_SESSION['uid'];
	$_POST['status'] = 0;
		
	if(DB::update('renthouse', $_POST, "rid='$rid' AND uid='{$_SESSION['uid']}'")) {
		showmessage('rent_edit_done', $_G['url']);
	} else {
		showmessage('rent_edit_error', $_G['url']);
	}
	
}

if($_GET['act'] == 'add' || $_GET['act'] == 'edit') {

	include libfile('class/editor');
	$row = array();
	
	if($_GET['act'] == 'add') {
		$head_title = lang("rent", "rent_add_title");
	} else {
		$head_title = lang("rent", "rent_edit_title");
		$rid = intval($_GET['rid']);
		$row = DB::getRow("SELECT * FROM ".DB::table('renthouse')." WHERE rid='$rid' AND uid='{$_SESSION['uid']}'");
		$row['config'] = unserialize($row['config']);
	}

	$editor = new editor();
	$body_editor = $editor->front_create('content', $row['content']);

	$region_select = show_select('region', 'regionid', $row['regionid']);
	$housetype1_select = show_select('housetype1', 'housetype1', $row['housetype1']);
	$housetype2_select = show_select('housetype2', 'housetype2', $row['housetype2']);
	$housetype3_select = show_select('housetype3', 'housetype3', $row['housetype3'], 'select_direction');
	$renttype_select = show_select('renttype1', 'renttype1');
	$rentpaytype_select = show_select('renttype1', 'rentpaytype');
	$config_checkbox = show_checkbox('houseconfig', 'config', $row['config']);	

	include template('rent/form');

}


?>